package cn.com.dycc.sys_manage.rolesysmanagement.controller;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.com.dycc.common.controller.BaseController;
import cn.com.dycc.sys_manage.rolesysmanagement.entity.Role;
import cn.com.dycc.sys_manage.rolesysmanagement.entity.RoleInfo;
import cn.com.dycc.sys_manage.rolesysmanagement.entity.RoleResult;
import cn.com.dycc.sys_manage.rolesysmanagement.service.RoleService;
import cn.com.dycc.util.JsonObjectResult;
import cn.com.dycc.util.JsonResult;
/**
 * 
 * Description: 角色信息控制层
 * Author: linfangan
 * Version: 1.0
 * Create Date Time: 2017年8月8日 下午4:37:30.
 * Update Date Time: 
 * @see
 */
@Controller
@RequestMapping("/role")
public class RoleController extends BaseController{
	
	@Resource(name="roleService")
	private RoleService roleService;
	
	//判断角色是否存在
	@RequestMapping("/judrole.do")
	@ResponseBody
	public JsonObjectResult addRole(Role role,HttpServletRequest  request){
		String opt_user_id = request.getSession().getAttribute("id").toString();
		String org_id = request.getSession().getAttribute("org_id").toString();
		role.setOpt_user_id(opt_user_id);
		role.setOrg_id(org_id);
//		System.out.println(bindRoleNo);
		boolean b = roleService.addRole(role);
		return new JsonObjectResult(b);
	}
	
	//查找角色信息,全显示
	//20180508更改
	@RequestMapping("/findrole.do")
	@ResponseBody
	public JsonObjectResult findAll(HttpServletRequest request,Integer page,Integer limit) throws IOException{
		String org_id = request.getSession().getAttribute("org_id").toString();
		List<RoleResult> list = roleService.findAll(org_id, page, limit);
		String count = roleService.findRoleListCount(request);
		return new JsonObjectResult(count,list);
	}

	//删除角色信息
	@RequestMapping("/delrole.do")
	@ResponseBody
	public JsonObjectResult deleteRoleByRoleNo(String role_no,HttpServletRequest  request){
		String org_id = request.getSession().getAttribute("org_id").toString();
		String message = roleService.deleteRoleByRoleNo(role_no,org_id);
		return new JsonObjectResult(message);
	}
	
	//查询所有的角色信息，用于用户的角色分配，不含隐藏
	@RequestMapping("/rolall.do")
	@ResponseBody
	public JsonObjectResult findAllNameOf(HttpServletRequest  request){
		String org_id = request.getSession().getAttribute("org_id").toString();
		List<RoleInfo> listRoleName = roleService.findAllNameOf(org_id);
		return new JsonObjectResult(listRoleName);
	}
	
}
